package problema034;

public class DigitFactorials {

	public static void main(String[] args){
		System.out.println(digitFact());
	}
	
	public static int digitFact(){
		int n = 0, ult = 0, act = 0, res = 0; 
		for(int i = 10; i < 10000000; i++){
			n = i;
			while(n != 0){
				ult = n % 10;
				act += fact(ult);
				n = (n - ult) /10;
			}
			if(act == i) res += act;
			act = 0;
		}
		return res;
	}
	
	public static int fact(int n) {
        int res = 1; 
        for (int i = 1; i <= n; i++) {
            res *= i;
        }
        return res;
    }

}
